package com.fh.controller.collection;

import com.fh.controller.system.timer.ApplicationContextUtil;
import com.fh.service.building.RecordService;
import com.fh.service.building.bill.BillService;
import com.fh.service.building.message.SysMessageService;
import com.fh.util.*;
import com.gnete.security.crypt.Crypt;
import com.gnete.security.crypt.CryptException;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.Map;

/**
 * 新签名包测试用例(依赖新签名包gnete-bc-139.jar与gnete-security.jar)
 */
public class Collection {

    private BillService billService = (BillService) ApplicationContextUtil.getBean("billService");
    private RecordService recordService = (RecordService) ApplicationContextUtil.getBean("recordService");
    private SysMessageService sysMessageService = (SysMessageService) ApplicationContextUtil.getBean("sysMessageService");

    private static Log log = LogFactory.getLog(Collection.class);

    /**
     * 代收付代收、代付交易测试URL
     */
//    测试
//    private static final String SERVER_URL = "http://59.41.103.98:333/gzdsf/ProcessServlet";
//    正式
    private static final String SERVER_URL = "https://121.8.154.151/ProcessServlet";

    //代收付签约、银行卡验证交易测试URL
//	private static final String SERVER_URL = "http://59.41.103.98:9110/gzdsf/ProcessServlet";

    // 交易代码
    private static final String TRX_CODE = "100001";
    // 版本号
    private static final String VERSION = "04";
    // 数据格式
    private static final String DATA_TYPE = "2";
    // 处理级别
    private static final String LEVEL = "0";
    // 用户名
    private static final String USER_NAME = "operator"; // 测试
    private static final String USER_NAME_TYT = "00019140020609903"; // 天运通
    private static final String USER_NAME_TCWY = "00019140020610103"; // 天长物业
    // 用户密码
    private static final String USER_PASS = "ora_123456"; // 测试
    private static final String USER_PASS_TYT = "tyt_123456"; // 天运通
    private static final String USER_PASS_TCWY = "tcwy_123456"; // 天长物业
    // 业务代码（测试：10600，正式：14902）
//    private static final String BUSINESS_CODE = "10600";
    private static final String BUSINESS_CODE = "14902";
    // 银联网络商户ID
    private static final String MERCHANT_ID = "001053110000001"; //测试
    private static final String MERCHANT_ID_TYT = "000191400206099"; //天运通
    private static final String MERCHANT_ID_TCWY = "000191400206101"; //天长物业
    // 用户私钥密码
    private static final String PRIVATE_KEY_FILE_PASSWORD = "123456"; //测试
    private static final String PRIVATE_KEY_FILE_PASSWORD_TYT = "123456"; //天运通
    private static final String PRIVATE_KEY_FILE_PASSWORD_TCWY = "123456"; //天长物业
    // 总记录数（固定为1）
    private static final String TOTAL_ITEM = "1";
    // 记录序号（同一个请求唯一，建议从0001递增）
    private static final String SN = "0001";

    public static void main(String[] args) throws CryptException {
        Collection tp = new Collection();
        PageData pd = new PageData();
        tp.TestPayReq(pd);
    }

    /**
     * 验证签名信息
     *
     * @throws CryptException
     */
    private boolean verifySign(String strXML) throws CryptException {
        //签名(代收付系统JDK环境使用GBK编码，商户使用签名包时需传送GBK编码集)
        Crypt crypt = new Crypt("gbk");
//        String pathCer = this.getClass().getResource("").getPath() + "../../../../ora/cert/gzdsf.cer"; //测试
        String pathCer = this.getClass().getResource("").getPath() + "../../../../ora/cert/gnete_pds.cer"; //正式
//        System.out.println(pathCer);
        int iStart = strXML.indexOf("<SIGNED_MSG>");
        if (iStart != -1) {
            int end = strXML.indexOf("</SIGNED_MSG>");
            String signedMsg = strXML.substring(iStart + 12, end);
            log.info(signedMsg);
            String strMsg = strXML.substring(0, iStart) + strXML.substring(end + 13);
            //调用签名包验签接口(原文,签名,公钥路径)
            if (crypt.verify(strMsg, signedMsg, pathCer)) {
                log.info("verify ok");
                return true;
            } else {
                log.error("verify error");
                return false;
            }
        }
        return true;
    }

    /**
     * 数据签名
     * comment here
     *
     * @param strData
     * @return
     * @throws CryptException
     * @since gnete-ora 0.0.0.1
     */
    private String signMsg(String strData, String type) throws CryptException {
        String strRnt = "";
        //签名(代收付系统JDK环境使用GBK编码，商户使用签名包时需传送GBK编码集)
        Crypt crypt = new Crypt("gbk");
        String pathPfx;
//        pathPfx = this.getClass().getResource("").getPath() + "../../../../ora/MerCA/ORA@TEST1.p12"; //测试
        if (type.equals("0") || type.equals("1")) {
            pathPfx = this.getClass().getResource("").getPath() + "../../../../ora/MerCA/cps@00019140020609903.p12"; //天运通
        } else {
            pathPfx = this.getClass().getResource("").getPath() + "../../../../ora/MerCA/cps@00019140020610103.p12"; //天长物业
        }
        String strMsg = strData.replaceAll("<SIGNED_MSG></SIGNED_MSG>", "");
        //调用签名包签名接口(原文,私钥路径,密码)
//        String signedMsg = crypt.sign(strMsg, pathPfx, PRIVATE_KEY_FILE_PASSWORD); //测试
        String signedMsg;
        if (type.equals("0") || type.equals("1")) {
            signedMsg = crypt.sign(strMsg, pathPfx, PRIVATE_KEY_FILE_PASSWORD_TYT); //天运通
        } else {
            signedMsg = crypt.sign(strMsg, pathPfx, PRIVATE_KEY_FILE_PASSWORD_TCWY); //天长物业
        }
        return strData.replaceAll("<SIGNED_MSG></SIGNED_MSG>", "<SIGNED_MSG>" + signedMsg + "</SIGNED_MSG>");
    }

    /**
     * 修改账单
     * comment here
     *
     * @param id
     * @return
     * @throws Exception
     * @since gnete-ora 0.0.0.1
     */
    private void changeBill(int type, String id, int state, String reason,String req, PageData pd) throws Exception {
        String log = "";
        String title = "";
        PageData changePd = new PageData();
        changePd.put("ID", id);
        // 通过账单ID获取账单信息
        PageData cPd = billService.findById(changePd);
        String broom = cPd.getString("BUILDING_NAME") + cPd.getString("ROOM_NUM");
        String btype = cPd.getString("BILL_NAME");
        String btime = cPd.getString("START_DATE") + "至" + cPd.getString("END_DATE");
        String bpime = cPd.getString("PAY_DATE");
        String bmoney = cPd.getString("TOTAL_PRICE");
        changePd.put("UPDATE_DATE", DateUtil.getTime());
        changePd.put("COLLECTION_STATE", state);
        if (type == 1) {
            changePd.put("ACT_PAY_DATE", DateUtil.getDay());
            changePd.put("STATE", "eda58d7280554dd9918207d27e2d4654");
            title = "账单自动扣款成功！";
            log = broom + " 周期：" + btime + "，收费日期：" + bpime + " 的" + btype + "账单，总金额" + bmoney + "元，自动扣款成功！";
            // 保存流水记录
            PageData bpPd = new PageData();
            bpPd.put("ID", UuidUtil.get32UUID());
            bpPd.put("CREATE_ID", cPd.getString("CREATE_ID"));
            bpPd.put("CREATE_DATE", DateUtil.getTime());
            bpPd.put("SORT", 0);
            bpPd.put("IS_DEL", 0);
            bpPd.put("BILL_ID", id);
            bpPd.put("PAY_METHOD", "银行卡（代收）");
            bpPd.put("COLLECTION_TYPE", pd.getString("ALLOT_BILL"));
            bpPd.put("PAY_PRICE", bmoney);
            bpPd.put("PAY_TRANSACTION", req);
            bpPd.put("IS_RECEIPT", "0");
            bpPd.put("INFO", "0");
            bpPd.put("PRICE_TYPE", "0");
            billService.savebillpay(bpPd);
        } else if (type == 2) {
            title = "账单自动扣款失败！";
            log = broom + " 周期：" + btime + "，收费日期：" + bpime + " 的" + btype + "账单，总金额" + bmoney + "元，自动扣款失败：" + reason + "。";
        }
        billService.edit(changePd);

        // 保存操作记录
        PageData rPd = new PageData();
        rPd.put("ID", UuidUtil.get32UUID());
        rPd.put("SORT", 0);
        rPd.put("IS_DEL", 0);
        rPd.put("CREATE_ID", cPd.getString("CREATE_ID"));
        rPd.put("CREATE_DATE", DateUtil.getTime());
        rPd.put("DETAILS", log);
        rPd.put("OPERATOR", cPd.getString("NAME"));
        rPd.put("OPERA_TIME", DateUtil.getTime());
        rPd.put("CONTRACT_ID", "");
        rPd.put("BILL_ID", id);
        rPd.put("TENANT_ID", "");
        rPd.put("ALLOT_BILL", "");
//        System.out.println(rPd.toString());
        recordService.save(rPd);
        // 保存消息
        PageData mPd = new PageData();
        mPd.put("TITLE", title);
        mPd.put("CONTENT", log);
        mPd.put("TYPE", 1);
        mPd.put("RECEIVER_USERID", "");
        mPd.put("CREATE_USERID", cPd.getString("CREATE_ID"));
        mPd.put("CONTRACT_ID", "");
        mPd.put("BILL_ID", id);
        mPd.put("REMIND_TIME", DateUtil.getTime());
        mPd.put("BILL_NAME", btype);
//        System.out.println(mPd.toString());
        sysMessageService.saveMessage(mPd);

    }

    /**
     * 测试请求
     * comment here
     *
     * @throws CryptException
     * @since gnete-ora 0.0.0.1
     */
    public void TestPayReq(PageData pd) throws CryptException {
        String req = System.currentTimeMillis() + "";

        // 交易流水号
        String REQ_SN = (DateUtil.getTimes() + UuidUtil.get32UUID()).substring(0, 25);
        // 交易总金额（整数，单位为分）
        Double totalPrice = Double.parseDouble(pd.getString("TOTAL_PRICE")) * 100;
        String TOTAL_SUM = Integer.valueOf(totalPrice.intValue()).toString();
        // 提交时间
        String SUBMIT_TIME = DateUtil.getTimes();
        // 银行代码
        String BANK_CODE = pd.getString("BANK_CODE");
        // 账号类型
        String ACCOUNT_TYPE = pd.getString("ACCOUNT_TYPE");
        // 账号
        String ACCOUNT_NO = pd.getString("ACCOUNT_NO");
        // 账号名
        String ACCOUNT_NAME = pd.getString("ACCOUNT_NAME");
        // 开户行所在省
        String PROVINCE = pd.getString("PROVINCE");
        // 开户行所在市
        String CITY = pd.getString("CITY");
        // 开户行名称
        String BANK_NAME = pd.getString("BANK_NAME");
        // 账号属性
        String ACCOUNT_PROP = pd.getString("ACCOUNT_PROP");
        // 金额
        String AMOUNT = TOTAL_SUM;
        // 货币类型
        String CURRENCY = pd.getString("CURRENCY");
        // 开户证件类型
        String ID_TYPE = pd.getString("ID_TYPE");
        // 证件号
        String ID = pd.getString("ID_CARD");
        // 开户联系方式
        String TEL = pd.getString("TEL");
        // 备注（账单ID）
        String REMARK = pd.getString("ID");
        // 账单类别
        String BILL_TYPE;
        if (pd.getString("BILL_TYPE") == null || pd.getString("BILL_TYPE").equals("")) {
            BILL_TYPE = "2";
        } else {
            BILL_TYPE = pd.getString("BILL_TYPE");
        }

        String strSendData;
        //请求报文 实时代收
        /*strSendData = "<?xml version=\"1.0\" encoding=\"GBK\"?>" +
                "<GZELINK>" +
                "  <INFO>" +
                "    <TRX_CODE>" + TRX_CODE + "</TRX_CODE>" +
                "    <VERSION>" + VERSION + "</VERSION>" +
                "    <DATA_TYPE>" + DATA_TYPE + "</DATA_TYPE>" +
                "    <LEVEL>" + LEVEL + "</LEVEL>" +
                "    <USER_NAME>" + USER_NAME + "</USER_NAME>" +
                "    <USER_PASS>" + USER_PASS + "</USER_PASS>" +
                "    <REQ_SN>" + REQ_SN + "</REQ_SN>" +
                "    <SIGNED_MSG></SIGNED_MSG>" +
                "  </INFO>" +
                "  <BODY>" +
                "    <TRANS_SUM>" +
                "      <BUSINESS_CODE>" + BUSINESS_CODE + "</BUSINESS_CODE>" +
                "      <MERCHANT_ID>" + MERCHANT_ID + "</MERCHANT_ID>" +
                "      <SUBMIT_TIME>" + SUBMIT_TIME + "</SUBMIT_TIME>" +
                "      <TOTAL_ITEM>" + TOTAL_ITEM + "</TOTAL_ITEM>" +
                "      <TOTAL_SUM>" + TOTAL_SUM + "</TOTAL_SUM>" +
                "    </TRANS_SUM>" +
                "    <TRANS_DETAILS>" +
                "      <TRANS_DETAIL>" +
                "        <SN>" + SN + "</SN>" +
                "        <E_USER_CODE/>" +
                "        <BANK_CODE>" + BANK_CODE + "</BANK_CODE>" +
                "        <ACCOUNT_TYPE>" + ACCOUNT_TYPE + "</ACCOUNT_TYPE>" +
                "        <ACCOUNT_NO>" + ACCOUNT_NO + "</ACCOUNT_NO>" +
                "        <ACCOUNT_NAME>" + ACCOUNT_NAME + "</ACCOUNT_NAME>" +
                "        <PROVINCE>" + PROVINCE + "</PROVINCE>" +
                "        <CITY>" + CITY + "</CITY>" +
                "        <BANK_NAME>" + BANK_NAME + "</BANK_NAME>" +
                "        <ACCOUNT_PROP>" + ACCOUNT_PROP + "</ACCOUNT_PROP>" +
                "        <AMOUNT>" + AMOUNT + "</AMOUNT>" +
                "        <CURRENCY>" + CURRENCY + "</CURRENCY>" +
                "        <PROTOCOL/>" +
                "        <PROTOCOL_USERID/>" +
                "        <ID_TYPE>" + ID_TYPE + "</ID_TYPE>" +
                "        <ID>" + ID + "</ID>" +
                "        <TEL>" + TEL + "</TEL>" +
                "        <CUST_USERID/>" +
                "        <RECKON_ACCOUNT></RECKON_ACCOUNT>" +
                "        <REMARK>" + REMARK + "</REMARK>" +
                "        <RESERVE1/>" +
                "        <RESERVE2/>" +
                "      </TRANS_DETAIL>" +
                "    </TRANS_DETAILS>" +
                "  </BODY>" +
                "</GZELINK>";*/

        //请求报文 批量代收
        if (BILL_TYPE.equals("0") || BILL_TYPE.equals("1")) {
            strSendData = "<?xml version=\"1.0\" encoding=\"GBK\"?>" +
                    "<GZELINK> " +
                    "  <INFO> " +
                    "    <TRX_CODE>" + TRX_CODE + "</TRX_CODE>" +
                    "    <VERSION>" + VERSION + "</VERSION>" +
                    "    <DATA_TYPE>" + DATA_TYPE + "</DATA_TYPE>" +
                    "    <LEVEL>" + LEVEL + "</LEVEL>" +
                    "    <USER_NAME>" + USER_NAME_TYT + "</USER_NAME>" +
                    "    <USER_PASS>" + USER_PASS_TYT + "</USER_PASS>" +
                    "    <REQ_SN>" + req + "</REQ_SN>  " +
                    "    <SIGNED_MSG></SIGNED_MSG> " +
                    "  </INFO>  " +
                    "  <BODY> " +
                    "    <TRANS_SUM> " +
                    "      <BUSINESS_CODE>" + BUSINESS_CODE + "</BUSINESS_CODE>" +
                    "      <MERCHANT_ID>" + MERCHANT_ID_TYT + "</MERCHANT_ID>" +
                    "      <SUBMIT_TIME>" + SUBMIT_TIME + "</SUBMIT_TIME>" +
                    "      <TOTAL_ITEM>" + TOTAL_ITEM + "</TOTAL_ITEM>" +
                    "      <TOTAL_SUM>" + TOTAL_SUM + "</TOTAL_SUM>" +
                    "    </TRANS_SUM>  " +
                    "    <TRANS_DETAILS> " +
                    "      <TRANS_DETAIL> " +
                    "        <SN>" + SN + "</SN>" +
                    "        <E_USER_CODE/>" +
                    "        <BANK_CODE>" + BANK_CODE + "</BANK_CODE>" +
                    "        <ACCOUNT_TYPE>" + ACCOUNT_TYPE + "</ACCOUNT_TYPE>" +
                    "        <ACCOUNT_NO>" + ACCOUNT_NO + "</ACCOUNT_NO>" +
                    "        <ACCOUNT_NAME>" + ACCOUNT_NAME + "</ACCOUNT_NAME>" +
                    "        <PROVINCE>" + PROVINCE + "</PROVINCE>" +
                    "        <CITY>" + CITY + "</CITY>" +
                    "        <BANK_NAME>" + BANK_NAME + "</BANK_NAME>" +
                    "        <ACCOUNT_PROP>" + ACCOUNT_PROP + "</ACCOUNT_PROP>" +
                    "        <AMOUNT>" + AMOUNT + "</AMOUNT>" +
                    "        <CURRENCY>" + CURRENCY + "</CURRENCY>" +
                    "        <PROTOCOL/>" +
                    "        <PROTOCOL_USERID/>" +
                    "        <ID_TYPE>" + ID_TYPE + "</ID_TYPE>" +
                    "        <ID>" + ID + "</ID>" +
                    "        <TEL>" + TEL + "</TEL>" +
                    "        <CUST_USERID/>" +
                    "        <RECKON_ACCOUNT></RECKON_ACCOUNT>" +
                    "        <REMARK>" + REMARK + "</REMARK>" +
                    "        <RESERVE1/>" +
                    "        <RESERVE2/>" +
                    "      </TRANS_DETAIL>  " +
                    "    </TRANS_DETAILS> " +
                    "  </BODY>" +
                    "</GZELINK>";
        } else {
            strSendData = "<?xml version=\"1.0\" encoding=\"GBK\"?>" +
                    "<GZELINK> " +
                    "  <INFO> " +
                    "    <TRX_CODE>" + TRX_CODE + "</TRX_CODE>" +
                    "    <VERSION>" + VERSION + "</VERSION>" +
                    "    <DATA_TYPE>" + DATA_TYPE + "</DATA_TYPE>" +
                    "    <LEVEL>" + LEVEL + "</LEVEL>" +
                    "    <USER_NAME>" + USER_NAME_TCWY + "</USER_NAME>" +
                    "    <USER_PASS>" + USER_PASS_TCWY + "</USER_PASS>" +
                    "    <REQ_SN>" + req + "</REQ_SN>  " +
                    "    <SIGNED_MSG></SIGNED_MSG> " +
                    "  </INFO>  " +
                    "  <BODY> " +
                    "    <TRANS_SUM> " +
                    "      <BUSINESS_CODE>" + BUSINESS_CODE + "</BUSINESS_CODE>" +
                    "      <MERCHANT_ID>" + MERCHANT_ID_TCWY + "</MERCHANT_ID>" +
                    "      <SUBMIT_TIME>" + SUBMIT_TIME + "</SUBMIT_TIME>" +
                    "      <TOTAL_ITEM>" + TOTAL_ITEM + "</TOTAL_ITEM>" +
                    "      <TOTAL_SUM>" + TOTAL_SUM + "</TOTAL_SUM>" +
                    "    </TRANS_SUM>  " +
                    "    <TRANS_DETAILS> " +
                    "      <TRANS_DETAIL> " +
                    "        <SN>" + SN + "</SN>" +
                    "        <E_USER_CODE/>" +
                    "        <BANK_CODE>" + BANK_CODE + "</BANK_CODE>" +
                    "        <ACCOUNT_TYPE>" + ACCOUNT_TYPE + "</ACCOUNT_TYPE>" +
                    "        <ACCOUNT_NO>" + ACCOUNT_NO + "</ACCOUNT_NO>" +
                    "        <ACCOUNT_NAME>" + ACCOUNT_NAME + "</ACCOUNT_NAME>" +
                    "        <PROVINCE>" + PROVINCE + "</PROVINCE>" +
                    "        <CITY>" + CITY + "</CITY>" +
                    "        <BANK_NAME>" + BANK_NAME + "</BANK_NAME>" +
                    "        <ACCOUNT_PROP>" + ACCOUNT_PROP + "</ACCOUNT_PROP>" +
                    "        <AMOUNT>" + AMOUNT + "</AMOUNT>" +
                    "        <CURRENCY>" + CURRENCY + "</CURRENCY>" +
                    "        <PROTOCOL/>" +
                    "        <PROTOCOL_USERID/>" +
                    "        <ID_TYPE>" + ID_TYPE + "</ID_TYPE>" +
                    "        <ID>" + ID + "</ID>" +
                    "        <TEL>" + TEL + "</TEL>" +
                    "        <CUST_USERID/>" +
                    "        <RECKON_ACCOUNT></RECKON_ACCOUNT>" +
                    "        <REMARK>" + REMARK + "</REMARK>" +
                    "        <RESERVE1/>" +
                    "        <RESERVE2/>" +
                    "      </TRANS_DETAIL>  " +
                    "    </TRANS_DETAILS> " +
                    "  </BODY>" +
                    "</GZELINK>";
        }

        HttpClient httpClient = new HttpClient();
        PostMethod postMethod =
                new PostMethod(SERVER_URL);
        //设置编码
        httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK");
        strSendData = this.signMsg(strSendData, BILL_TYPE);
        log.info("发送报文：" + strSendData);
        postMethod.setRequestBody(strSendData);
        try {
            long start = System.currentTimeMillis();
            //执行getMethod
            int statusCode = httpClient.executeMethod(postMethod);
            System.out.println("cost:" + (System.currentTimeMillis() - start));
            //失败
            if (statusCode != HttpStatus.SC_OK) {
                log.error("Method failed: " + postMethod.getStatusLine());
                //读取内容
                byte[] responseBody = postMethod.getResponseBody();
                //处理内容
                String strResp = new String(responseBody, "GBK");
                log.error("失败，服务器返回:" + strResp);
                Map map = ParseXmlUtil.xml2map(strResp, false);
                JSON json = JSONObject.fromObject(map);
                System.out.println("扣款失败");
                System.out.println(json.toString(1)); // 格式化输出
            } else {
                //读取内容
                byte[] responseBody = postMethod.getResponseBody();
                String strResp = new String(responseBody, "GBK");
                log.info("服务器返回:" + strResp);
                //验签
                if (this.verifySign(strResp)) {
                    log.info("验签正确，处理服务器返回的报文");
                    Map map = ParseXmlUtil.xml2map(strResp, false);
                    JSON json = JSONObject.fromObject(map);
//                    System.out.println(json.toString(1)); // 格式化输出
                    JSONObject jsonObject = JSONObject.fromObject(json);
                    String info_code = "";
                    String info_msg = "";
                    String body_code = "";
                    String body_msg = "";
                    if (map.get("INFO") != null && !map.get("INFO").toString().equals("")) {
                        JSONObject INFO = JSONObject.fromObject(jsonObject.getJSONObject("INFO"));
                        info_code = INFO.get("RET_CODE").toString();
                        info_msg = INFO.get("ERR_MSG").toString();
                    }
                    if (map.get("BODY") != null && !map.get("BODY").toString().equals("")) {
                        JSONObject BODY = JSONObject.fromObject(jsonObject.getJSONObject("BODY"));
                        JSONObject RET_DETAILS = JSONObject.fromObject(BODY.getJSONObject("RET_DETAILS"));
                        JSONObject RET_DETAIL = JSONObject.fromObject(RET_DETAILS.getJSONObject("RET_DETAIL"));
                        body_code = RET_DETAIL.get("RET_CODE").toString();
                        if (RET_DETAIL.get("ERR_MSG") != null && !RET_DETAIL.get("ERR_MSG").equals("")) {
                            body_msg = RET_DETAIL.get("ERR_MSG").toString();
                        }
                    }
                    if (info_code.equals("0000")) {
                        if (body_code.equals("0000")) {
                            // 将此条账单置为支付成功状态
                            changeBill(1, REMARK, 1, "扣款成功", req, pd);
                        } else {
                            // 将此条账单置为支付失败状态并保存操作记录
                            changeBill(2, REMARK, 2, body_msg, req, pd);
                        }
                    } else {
                        // 将此条账单置为支付失败状态并保存操作记录
                        changeBill(2, REMARK, 2, info_msg, req, pd);
                    }
                }
            }
        } catch (HttpException e) {
            //发生致命的异常，可能是协议不对或者返回的内容有问题
            log.error("Please check your provided http address!", e);
            e.printStackTrace();
        } catch (IOException e) {
            //发生网络异常
            log.error(e);
        } catch (Exception e) {
            log.error(null, e);
        } finally {
            //释放连接
            postMethod.releaseConnection();
        }
    }


}
